{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualization of supported behavior model for cars and pedestrian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "using AutomotivePOMDPs, AutoViz, AutomotiveDrivingModels\n",
    "using Reel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "cam = FitToContentCamera(0.)\n",
    "rng = MersenneTwister(1);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Intelligent Pedestrian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "env = CrosswalkEnv()\n",
    "env.obstacles = ConvexPolygon[] # no obstacles\n",
    "pomdp = OCPOMDP(env=env); # to have convenient functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<video autoplay controls><source src=\"files/reel-11163952646769224376.webm?17908321676968333081\" type=\"video/webm\"></video>"
      ],
      "text/plain": [
       "Reel.Frames{MIME{Symbol(\"image/png\")}}(\"/tmp/tmps1fbpw\", 0x0000000000000065, 10.0, nothing)"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scene = Scene()\n",
    "ego = Vehicle(VehicleState(VecSE2(10., 0., 0.0), env.roadway, 6.), VehicleDef(), 1)\n",
    "push!(scene, ego)\n",
    "ped =  Vehicle(VehicleState(Frenet(env.crosswalk, 5.), env.roadway, 1.), AutomotivePOMDPs.PEDESTRIAN_DEF, 2)\n",
    "push!(scene, ped)\n",
    "\n",
    "models = Dict{Int64, DriverModel}()\n",
    "models[ego.id] = IntelligentDriverModel(v_des=5.) # follow its own lane\n",
    "models[ped.id] = IntelligentPedestrian(crosswalk=env.crosswalk, conflict_lanes=get_conflict_lanes(env.crosswalk, env.roadway))\n",
    "\n",
    "nticks = 100\n",
    "timestep = 0.1\n",
    "rec = SceneRecord(nticks+1, timestep)\n",
    "# execute the simulation\n",
    "simulate!(rec, scene, env.roadway, models, nticks)\n",
    "duration, fps, render_rec = animate_record(env, rec, sim_dt=timestep, cam=cam, overlays=SceneOverlay[IDOverlay()])\n",
    "film = roll(render_rec, fps = fps, duration = duration)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.6.1",
   "language": "julia",
   "name": "julia-0.6"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
